<?php

class Empeval_AuthData_Email implements Empeval_AuthData_ILoginData {
	
	private $email;
	private $password;
	
	public function __construct($email, $password) {
		$this->email = $email;
		$this->password = $password;
	}
	
	public function getUser() {
		return EmpevalUsersQuery::create()
			->withRoles()
			->withPosition()
			->filterByEmail($this->email)
			->filterByPassword($this->crypt($this->password))
			->filterByActive(true)
			->filterByDeleted(null, Criteria::ISNULL)
			->find()
			->getFirst();
	}
	
	public function getId() {
		return $this->email;
	}
	
	private function crypt($data) {
		return hash('sha256', $this->password);
	}
	
}